package com.texaco.chapasFutbol.scene;

import org.andengine.engine.camera.Camera;
import org.andengine.entity.scene.background.Background;
import org.andengine.entity.scene.background.SpriteBackground;
import org.andengine.entity.sprite.Sprite;
import org.andengine.entity.text.Text;
import org.andengine.util.progress.IProgressListener;

import com.texaco.chapasFutbol.R;
import com.texaco.chapasFutbol.buttons.Button;
import com.texaco.chapasFutbol.buttons.IButtonCallBack;
import com.texaco.chapasFutbol.entidades.Game;
import com.texaco.chapasFutbol.resources.Resources;

/**
 * Clase que implementa la escena de resumen de una partida.
 * @author texaco
 *
 */
public class SummaryScene extends SceneBase{

	private Text mTextoResumen;

	public SummaryScene(Game game){
		super(game);
	}

	@Override
	public void initAsync(IProgressListener pProgressListener) {
		android.content.res.Resources resources = this.game.getActivity().getResources();
		
		this.setBackground(
				new SpriteBackground(
						new Sprite(0,0, 
								this.game.getActivity().getShapesMaps().get(Game.OPTIONS_BACKGROUND_SHAPE),
								this.game.getActivity().getVertexBufferObjectManager())));
		
		String textoResumen = "Equipo Local: " + this.game.getHud().getMarcadorLocal()
				+ "\nEquipo Visitante: " + this.game.getHud().getMarcadorVisitante()
				+ "\nEquipo ganador: " + this.game.getEquipoGanador();

		this.mTextoResumen = new Text(resources.getInteger(R.integer.layout_left_margin), 
				resources.getInteger(R.integer.layout_top_margin), 
				this.game.getActivity().getFontMap().get(Resources.FONT_OPTIONS_CAPTION), 
				textoResumen,
				130, 
				this.game.getActivity().getVertexBufferObjectManager());
		
		this.attachChild(this.mTextoResumen);

		Button bBack = new Button(this.game, 
				this, 
				500, 
				500, 
				R.string.tLabelButtonBack, 
				this.game.getActivity().getFontMap().get(Resources.FONT_OPTIONS), 
				Game.BOTON_SIGUIENTE_SHAPE,
				new IButtonCallBack() {
					public String fire() {
						SummaryScene.this.game.getActivity().getSoundHandler().playFx(Resources.SOUND_CLICK);
						SummaryScene.this.game.loadMenuPrincipalScene();
						return null;
					}
				});
		Camera camera = this.game.getActivity().getEngine().getCamera();
		bBack.setPosition(camera.getWidth() - bBack.getWidth() - resources.getInteger(R.integer.layout_right_margin), 
				camera.getHeight() - bBack.getHeight() - resources.getInteger(R.integer.layout_bottom_margin));
	}

	@Override
	protected void update() {
		String textoResumen = this.game.getActivity().getText(R.string.tLocalTeamLabel) + ": "
				+ this.game.getHud().getMarcadorLocal() + "\n"
				+ this.game.getActivity().getText(R.string.tVisitantTeamLabel)
				+ ": " + this.game.getHud().getMarcadorVisitante() + "\n"
				+ this.game.getActivity().getText(R.string.tWinnerLabel) + ": "
				+ this.game.getEquipoGanador();

		this.mTextoResumen.setText(textoResumen);
	}

	@Override
	protected boolean async() {
		return true;
	}
}